package com.hnguigu.health.houduan.lq.service_lq.impl;

import com.hnguigu.health.houduan.lq.service_lq.TUserConstitutionTableService;
import com.hnguigu.health.mapper.TPhysicalTableMapper;
import com.hnguigu.health.mapper.TUserConstitutionTableMapper;
import com.hnguigu.health.pojo.TPhysicalTable;
import com.hnguigu.health.pojo.TUserConstitutionTable;
import com.hnguigu.health.pojo.TUserPsychologicalEvaluation;
import com.hnguigu.health.utils.RequseionallAnswer;
import com.hnguigu.health.utils.UserContionXz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TUserConstitutionTableServiceImpl implements TUserConstitutionTableService {
    @Autowired(required = false)
    TUserConstitutionTableMapper tUserConstitutionTableMapper;
    @Autowired(required = false)
    TPhysicalTableMapper tPhysicalTableMapper;

    @Override
    public  Map<Integer,List<RequseionallAnswer>> selectAllTUserConstitution(String tMerBerid) {
        Map<Integer,List<RequseionallAnswer>> map=new HashMap<>();
        List<TPhysicalTable> tPhysicalTables = tPhysicalTableMapper.selectTphysicaltable();
        List<TUserConstitutionTable> tUserConstitutionTables = tUserConstitutionTableMapper.selectAllTUserConstitution(tMerBerid);
        for (TPhysicalTable tPhysicalTable : tPhysicalTables) {
            List<RequseionallAnswer> aa=new ArrayList<>();
            for (TUserConstitutionTable tUserConstitutionTable : tUserConstitutionTables) {
                RequseionallAnswer answer=new RequseionallAnswer();
                if(tUserConstitutionTable.getTUserPhysiqueId()==tPhysicalTable.getTPhysiqueId()){
                    answer.setId(tUserConstitutionTable.getTUserChooseIssueId());
                    answer.setVal(tUserConstitutionTable.getTUserChooseValue());
                    aa.add(answer);
                }
            }
            map.put(tPhysicalTable.getTPhysiqueId(),aa);
        }

        return map;
    }

    @Override
    public int addUserConstitution(UserContionXz userContionXz) {
        return tUserConstitutionTableMapper.addUserConstitution(userContionXz);
    }

    @Override
    public int deleteByTmerber(String tmerber) {
        return tUserConstitutionTableMapper.deleteByTmerber(tmerber);
    }

    @Override
    public TUserConstitutionTable tcbyTmerberLast(String tmerber) {
        List<TUserConstitutionTable> TUserConstitutionTables = tUserConstitutionTableMapper.selectAllTUserConstitution(tmerber);

        return TUserConstitutionTables.get(TUserConstitutionTables.size()-1);
    }


}
